// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   PolygonUtils.java

package jones.gui;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;

public class PolygonUtils
{

    private static Polygon awtPolygon = new Polygon();

    public PolygonUtils()
    {
    }

    public static void draw(jones.rigid.Polygon rigidPolygon, Graphics2D g2d)
    {
        drawPolygon(rigidPolygon, ((Graphics) (g2d)));
    }

    public static void fill(jones.rigid.Polygon rigidPolygon, Graphics2D g2d)
    {
        g2d.fill(((java.awt.Shape) (getAWTPolygon(rigidPolygon, awtPolygon))));
    }

    public static Polygon getAWTPolygon(jones.rigid.Polygon rigidPolygon, Polygon awtPolygon)
    {
        if (awtPolygon == null)
        {
            int n = rigidPolygon.getN();
            awtPolygon = new Polygon(new int[n], new int[n], n);
        } else
        {
            awtPolygon.reset();
        }
        for (int i = 0; i < rigidPolygon.getN(); i++)
            awtPolygon.addPoint((int)Math.round(rigidPolygon.getX(i)), (int)Math.round(rigidPolygon.getY(i)));

        return awtPolygon;
    }

    public static void drawPolygon(jones.rigid.Polygon p, Graphics g)
    {
        int n = p.getN();
        for (int i = 0; i < n; i++)
            g.drawLine((int)p.getX(i), (int)p.getY(i), (int)p.getX((i + 1) % n), (int)p.getY((i + 1) % n));

    }

}
